/// 应用路由配置
/// 
/// 使用go_router进行路由管理
/// 定义所有页面的路由路径和配置
/// 
/// 作者: Fluttert Team
/// 日期: 2024

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../views/splash/splash_page.dart';
import '../views/home/home_page.dart';
import '../views/user/user_list_page.dart';
import '../views/user/user_detail_page.dart';

/// 路由配置类
/// 
/// 集中管理应用的所有路由定义
class AppRoutes {
  /// 启动页路由路径
  static const String splash = '/';
  
  /// 首页路由路径
  static const String home = '/home';
  
  /// 用户列表页路由路径
  static const String userList = '/users';
  
  /// 用户详情页路由路径
  static const String userDetail = '/users/detail';

  /// 路由配置实例
  /// 
  /// 使用GoRouter实现声明式路由
  /// initialLocation: 设置应用启动时的初始路由
  static final GoRouter router = GoRouter(
    initialLocation: splash,
    routes: [
      GoRoute(
        path: splash,
        name: 'splash',
        builder: (context, state) => const SplashPage(),
      ),
      GoRoute(
        path: home,
        name: 'home',
        builder: (context, state) => const HomePage(),
      ),
      GoRoute(
        path: userList,
        name: 'userList',
        builder: (context, state) => const UserListPage(),
      ),
      GoRoute(
        path: '$userDetail/:id',
        name: 'userDetail',
        builder: (context, state) {
          final id = state.pathParameters['id'];
          final user = state.extra;
          return UserDetailPage(
            userId: id,
            user: user is Map ? null : user,
          );
        },
      ),
    ],
  );
}

